<template>
	<view class="all-main">
		<view class="main">
			<view class="lists">
				<view v-for="(item, index) in bankList" :key="index" class="items">
					<view class="bank_info">
						<img :src="item.bank_logo" alt="">
						<view class="numbers">
							<text>(尾号{{item.card_number}})</text>
						</view>
					</view>
					<view class="bank_account">
						<text>{{item.name}}</text>
						<text>{{item.phone}}</text>
					</view>
					<view class="operates">
						<view class="btns">
							<u-tag text="修改" size="mini" @click="edit(item)"></u-tag>
						</view>
						<view class="btns">
							<u-tag text="删除" size="mini" type="error" @click="del(item)"></u-tag>
						</view>
					</view>
				</view>
			</view>
			<view class="addBtn" @click="add">
				<u-icon name="plus" color="#ffffff"></u-icon>
				<text>添加</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bank_logo: 'http://img.lundroid.com/e4aa64.png',
				bankList: [],
			}
		},
		onLoad() {
			this.getBankList()
		},
		methods: {
			// 获取账号
			async getBankList() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'bankcard/getBankList'
				});
				uni.hideLoading()
				if (res.code == 200) {
					this.bankList = res.data.map((item) => {
						item.card_number = item.bank_card_number.slice(-4)
						return item
					})
				}
			},
			// 添加
			add() {
				uni.navigateTo({
					url: '/pages/mine/bank/add'
				})
			},
			// 修改
			edit(item) {
				uni.navigateTo({
					url: '/pages/mine/bank/edit?id=' + item.id
				})
			},
			// 删除
			del(item) {
				var _this = this
				uni.showModal({
					title: '提示',
					content: '账户删除后无法恢复，确定要删除该账户吗？',
					success: function(ress) {
						if (ress.confirm) {
							_this.accountDel(item)
						}
					}
				});
			},
			// 账户删除
			async accountDel(item) {
				var _this = this
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'bankcard/delBank',
					data: {
						id: item.id
					}
				});
				uni.hideLoading()
				uni.showToast({
					title: res.msg,
					icon: 'none',
					duration: 1000
				})
				if (res.code == 200) {
					setTimeout(function() {
						_this.getBankList()
					}, 1000)
				}
			},
		}
	}
</script>

<style lang="scss">
	.all-main {
		.main {
			padding: 30rpx;
			
			.lists {
				margin-bottom: 100rpx;
				
				.items {
					border-radius: 10rpx;
					box-shadow: 7px 0px 30px -18px #888888;
					
					.bank_info {
						display: flex;
						justify-content: space-between;
						align-items: center;
						padding: 20rpx;
						// border-bottom: 1px solid #eee;
						
						img {
							width: 200rpx;
						}
						
						.numbers {
							font-weight: bold;
						}
					}
					
					.bank_account {
						font-size: 30rpx;
						padding: 20rpx 40rpx;
						// border-bottom: 1px solid #eee;
						
						text {
							padding-right: 20rpx;
						}
					}
					
					.operates {
						padding: 20rpx;
						display: flex;
						justify-content: flex-end;
						
						.btns {
							padding-left: 20rpx;
						}
					}
				}
				
				.items:nth-child(1) {
					background-color: #fab6b6;
				}
				
				.items:nth-child(2) {
					background-color: #a0cfff;
				}
				
				.items:nth-child(3) {
					background-color: #fcbd71;
				}
				
				.items:nth-child(4) {
					background-color: #71d5a1;
				}
				
				.items:nth-child(5) {
					background-color: #fab6b6;
				}
				
				.items:nth-child(6) {
					background-color: #fcbd71;
				}
			}
			
			.addBtn {
				position: fixed;
				bottom: 0;
				left: 0;
				right: 0;
				background-color: #2979ff;
				color: #ffffff;
				text-align: center;
				display: flex;
				justify-content: center;
				align-items: center;
				padding: 30rpx;
				
				text {
					padding-left: 10rpx;
				}
			}
		}
	}
</style>
